package com.liyuan.help_e.dao;

import com.liyuan.help_e.model.Comment;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface CommentDao {
    @Insert("insert into comment (parentId,type,user,commentCount,createdAt,praiseCount,content)values(#{parentId},#{type},#{user.id},#{commentCount},#{createdAt},#{praiseCount},#{content})")
    void insertComment(Comment comment);

    @Select("select * from comment where parentId = #{parentId} and type = #{type} order by createdAt desc")
    Comment[] selectComments(@Param("type") Integer type,
                             @Param("parentId") Integer questionId);

    @Update("update comment set praiseCount = praiseCount + 1 where id = #{commentId}")
    void praise(Integer commentId);

    @Update("update comment set commentCount = commentCount +1 where id = #{parentId}")
    void increCommentCount(Integer parentId);



    @Select("select * from comment where id = #{id}")
    Comment selectCommentById(@Param("id") Integer parentId);

    @Select("select LAST_INSERT_ID(); ")
    Integer selectLastInsertId();
}
